package com;
import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jasig.cas.client.authentication.AttributePrincipal;
import org.jasig.cas.client.util.AssertionHolder;


public class LoginServlet extends HttpServlet {
	
	@Override
	public void init() throws ServletException {
		super.init();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			String username = AssertionHolder.getAssertion().getPrincipal().getName();  
	        AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();  
	        Map<String, Object> attributes = principal.getAttributes();  
	        String email= (String)attributes.get("email");  
	        response.getWriter().print("hello, " + username + " . email:" + email);  
	}

}
